<?php
/**
 * @version     1.0.0
 * @package     com_brinkmanvm
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Miguel Puig <miguel@freebandtech.com> - http://freebandtech.com
 */

defined('_JEXEC') or die;
abstract class BrinkmanvmHelper
{
	public static function test()
	{
		return '<img src="http://sandbox.freebandtech.com/brinkman/int/jupgrade/index.php?option=com_brinkmanvm&view=image&format=raw&p_sku=072557826" />';
	}
	public static function showImage($p_sku,$class="bkmImg",$Productid = false,$hideimage = false)
	{
		if($Productid): //get the sku from the product id
		
			$db = JFactory::getDbo();
			$query = $db->getQuery(true);
			$query->select('product_sku');
			$query->from('#__virtuemart_products');
			$query->where('virtuemart_product_id='.$p_sku);
			$db->setQuery($query);
			$p_sku = $db->loadResult();
		endif;
	
		$app = JFactory::getApplication('site');
		$componentParams = $app->getParams('com_brinkmanvm');
		$pathImages = $componentParams->get('pathimages', '/var/www/sandbox.freebandtech.com/brinkman/images_catalog/');
		$filename = $pathImages.'product/'.$p_sku.'.jpg';
		if($hideimage && !file_exists($filename)):
			$render = '';
		else:
			$render = '<img src="index.php?option=com_brinkmanvm&view=image&format=raw&p_sku='.$p_sku.'" class="'.$class.'"/>';
		endif;
		   
	
		return $render;
	}

}

